home *** CD-ROM | disk | FTP | other *** search
- head 1.1;
- branch ;
- access ;
- symbols ;
- locks brent:1.1; strict;
- comment @ * @;
-
-
- 1.1
- date 88.04.17.10.20.46; author brent; state Exp;
- branches ;
- next ;
-
-
- desc
- @Client side code for pseudo-device benchmark
- @
-
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @/*
- * client.c --
- *
- * The client part of some multi-program synchronization primatives.
- * The routines here interface to the server; initial contact,
- * waiting for the start message, and notification of completion.
- *
- * Copyright 1986 Regents of the University of California
- * All rights reserved.
- */
-
- #ifndef lint
- static char rcsid[] = "$Header: client.c,v 1.1 88/04/16 12:27:43 brent Exp $ SPRITE (Berkeley)";
- #endif not lint
-
-
- #include "sprite.h"
- #include "status.h"
- #include "io.h"
- #include "fs.h"
- #include "dev/pdev.h"
-
- extern char *pdev;
- extern Boolean select;
-
- char buffer[4096];
- int bufSize = sizeof(buffer);
-
- typedef struct ClientState {
- int clientStreamID;
- } ClientState;
-
- /*
- *----------------------------------------------------------------------
- *
- * ClientSetup --
- *
- * Establish contact with the server.
- *
- * Results:
- * A pointer to state about the clients needed by ClientStart and
- * ClientDone.
- *
- * Side effects:
- * Creates named pipes and communicates with server
- * This exits upon error.
- *
- *----------------------------------------------------------------------
- */
-
- void
- ClientSetup(dataPtr)
- ClientData *dataPtr;
- {
- ClientState *statePtr;
- ReturnStatus status;
-
- statePtr = (ClientState *)Mem_Alloc(sizeof(ClientState));
-
- status = Fs_Open(pdev, FS_READ|FS_WRITE, 0,
- &statePtr->clientStreamID);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientSetup: error opening pseudo device");
- Io_Flush(io_StdErr);
- Proc_Exit(status);
- }
- *dataPtr = (ClientData)statePtr;
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * ClientRead --
- *
- * Read from a pseudo-device. The amount and number of repetitions
- * can be varied for measurment.
- *
- * Results:
- * None
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- void
- ClientRead(data, size, reps)
- ClientData data;
- int size;
- register int reps;
- {
- ClientState *statePtr;
- int amountRead;
- register ReturnStatus status;
- register char *buffer = (char *)Mem_Alloc(size);
- register int i;
-
- statePtr = (ClientState *)data;
- for (i=0 ; i<reps ; i++) {
- amountRead = size;
- if (select) {
- int numReady;
- int mask = 1 << statePtr->clientStreamID;
- status = Fs_Select(32, NULL, &mask, NULL, NULL, &numReady);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientRead: error on select");
- break;
- }
- }
- status = Fs_Read(statePtr->clientStreamID, size, buffer, &amountRead);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientRead: error on read");
- break;
- } else if (amountRead != size) {
- Io_PrintStream(io_StdErr, "Read #%d was short (%d < %d)\n",
- i, amountRead, size);
- break;
- }
- if (size > 0 && buffer[0] != 'z') {
- Io_PrintStream(io_StdErr, "Bad data returned <%c>\n", buffer[0]);
- }
- }
- Mem_Free(buffer);
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * ClientWrite --
- *
- * Write from a pseudo-device. The amount and number of repetitions
- * can be varied for measurment.
- *
- * Results:
- * None
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- void
- ClientWrite(data, size, reps)
- ClientData data;
- int size;
- register int reps;
- {
- ClientState *statePtr;
- int amountWrite;
- register ReturnStatus status;
- register char *buffer = (char *)Mem_Alloc(size);
-
- statePtr = (ClientState *)data;
- do {
- status = Fs_Write(statePtr->clientStreamID, size, buffer, &amountWrite);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientWrite: error on read");
- break;
- } if (amountWrite != size) {
- Io_PrintStream(io_StdErr, "Short write %d < %d\n", amountWrite,
- size);
- }
- } while (--reps > 0);
- Mem_Free(buffer);
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * ClientIOControl --
- *
- * Do an IOControl to a pseudo-device.
- * The amount of data passed in and number of repetitions
- * can be varied for measurment.
- *
- * Results:
- * None
- *
- * Side effects:
- * None.
- *
- *----------------------------------------------------------------------
- */
-
- void
- ClientIOControl(data, size, reps)
- ClientData data;
- int size;
- register int reps;
- {
- ClientState *statePtr;
- int amountRead;
- register ReturnStatus status;
- register char *inBuffer = (char *)Mem_Alloc(size);
- register char *outBuffer = (char *)Mem_Alloc(size);
- int command;
-
- statePtr = (ClientState *)data;
- do {
- extern Boolean switchBuf;
- if (switchBuf && (reps % 7) == 0) {
- command = IOC_PDEV_SET_BUF;
- } else {
- command = 8 << 16; /* To avoid range of generic I/O controls */
- }
- status = Fs_IOControl(statePtr->clientStreamID, command, size, inBuffer,
- size, outBuffer);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientIOControl: error ");
- break;
- }
- } while (--reps > 0);
- Mem_Free(inBuffer);
- Mem_Free(outBuffer);
- }
-
- /*
- *----------------------------------------------------------------------
- *
- * ClientDone --
- *
- * Tell the server we're done. This is just done by closing
- * the pseudo stream.
- *
- * Results:
- * None
- *
- * Side effects:
- * None
- *
- *----------------------------------------------------------------------
- */
-
- void
- ClientDone(data)
- ClientData data;
- {
- ClientState *statePtr;
- register ReturnStatus status;
-
- statePtr = (ClientState *)data;
- status = Fs_Close(statePtr->clientStreamID);
- if (status != SUCCESS) {
- Stat_PrintMsg(status, "ClientDone: error on close");
- }
- }
- @
-